package server

import (
	"context"
	"google.golang.org/grpc"
	"net"
	pt "test_chat/protobuf"
)

const (
	post = "127.0.0.1:18887"
)

type server struct {
	pt.UnimplementedHellowServerServer
}

func (ss *server) SayHellow(ctx context.Context, in *pt.HellowRequest) (*pt.HellowReply, error) {
	return &pt.HellowReply{Message: "HI " + in.GetName()}, nil
}

func (ss *server) GetHellowMsg(ctx context.Context, in *pt.HellowRequest) (*pt.HellowMessage, error) {
	return &pt.HellowMessage{Msg: "get " + in.GetName()}, nil
}

//func (ss *server) mustEmbedUnimplementedHellowServerServer() {
//	fmt.Println("")
//}

func TestServer() {
	listen, err := net.Listen("tcp", post)
	if err != nil {
		panic(err)
	}
	srv := grpc.NewServer()
	pt.RegisterHellowServerServer(srv, &server{})
	err = srv.Serve(listen)
	if err != nil {
		panic(err)
	}
}
